class LeaveWordMgrController {

    def index = { }

    def saveToTeacherWord = {
        def leaveWordInstance = new LeaveWord(params)
        def teacherInstance = Teacher.get(params.teacherId)
        if(!teacherInstance){
            flash.message = "没有找到此教师"
            return redirect(controller:"teacher",action:"list")
        }
        leaveWordInstance.teacher = teacherInstance
        if (leaveWordInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'leaveWord.label', default: 'LeaveWord'), leaveWordInstance])}"
            redirect(controller:"teacher",action:"show",id:params.teacherId)
        }
        else {
            flash.message = "保存失败"
            //redirect(controller:"teacher",action:"show",id:params.teacherId)
            //chain(controller:"teacher",action:"show",model:[leaveWordInstance: leaveWordInstance],id:params.teacherId)
            render(view: "../teacher/show", model: [leaveWordInstance: leaveWordInstance,teacherInstance:teacherInstance])
        }
    }

    def saveToStudentWord = {
        def leaveWordInstance = new LeaveWord(params)
        def studentInstance = Student.get(params.studentId)
        if(!studentInstance){
            flash.message = "没有找到此学员"
            return redirect(controller:"student",action:"list")
        }
        leaveWordInstance.student = studentInstance
        if (leaveWordInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'leaveWord.label', default: 'LeaveWord'), leaveWordInstance])}"
            redirect(controller:"student",action:"show",id:params.studentId)
        }
        else {
            flash.message = "保存失败"
            render(view: "../student/show", model: [leaveWordInstance: leaveWordInstance,studentInstance:studentInstance])
        }
    }

    def teacherLeaveWordList = {    
        def teacherInstance = Teacher.get(params.id)
        def list = new ArrayList()
        if(teacherInstance){
            list = LeaveWord.findAllByTeacher(teacherInstance)             
        }
        [leaveWordList:list]
    }

   def studentLeaveWordList = {    
        def studentInstance = Student.get(params.id)
        def list = new ArrayList()
        if(studentInstance){
            list = LeaveWord.findAllByStudent(studentInstance)             
        }
        [leaveWordList:list]
    }
}
